'use strict';

module.exports = app => {
    const { STRING, INTEGER } = app.Sequelize;
    // actionId, contractProviderId_actionSelector, userAddr, arg, amount, userTimeStamp, sign, timeStamp, sign, timeStamp
    const Action = app.model.define('action', {
        id: { type: INTEGER, primaryKey: true, autoIncrement: true },
        uuid: { type: STRING, allowNull: false,unique:true },// CHAR
        actionSelector: { type: STRING(255), allowNull: false },
        parameter: { type: STRING(255) },
        userTimeStamp: { type: INTEGER, allowNull: false },// BIGINT
        srvTimestamp:  { type: INTEGER, allowNull: false },// BIGINT
        amount:  { type: INTEGER, allowNull: false },// BIGINT
        sign:  { type: STRING, allowNull: false },// CHAR
        actionAddress: { type: STRING, allowNull: false },
        accountId: { 
            type: INTEGER, allowNull: false,
        },
        ifFail: { type: INTEGER },
        isSettled: { type: INTEGER },
        blockNum: { type: INTEGER },
        isBuy: { type: INTEGER, allowNull: false },
        encodeParameters: { type: STRING, allowNull: false },
        allocation:  { type: INTEGER },// BIGINT
    });
    Action.associate = function() {
        // 
        app.model.Action.belongsTo(app.model.Account, { foreignKey: 'accountId',targetKey:'id'});
    }

    return Action;
};